import java.io.IOException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import date.DateParser;
import Server.Client;
import SystemDataTypes.FlightData;
import SystemDataTypes.Vector3;


public class SendFlightData {

	/**
	 * @param args
	 */
	
	static String sendToHost;
	static int sendToPort;

	public static void main(String[] args) {
		
		// MANDAMOS A:
		sendToHost = "localhost";
		sendToPort = 4019;
		
        // LOS DATOS DEL VUELO SON:		
		String position = "[0,0,0.5]";
		double speed = 1;
		int flightId = 3;
		String source = "Radar"; // Radar, Manual, Transceptor
		int demora = 0;

		////////////////////////////////////////////////////
		
        JSONArray v;
		try {
			v = new JSONArray(position);
        FlightData fd1 = new FlightData(speed,
        new Vector3(v.getDouble(0),v.getDouble(1),v.getDouble(2)), 
        flightId, 
        source,  
        demora);                                     
                       
        JSONObject js = new JSONObject();
        js.put("nOrden", DateParser.toString(new java.util.Date()));
        js.put("data",fd1.toString());                              
        sendData(fd1.toString());               
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}                                                          
	}
	
	private static void sendData(String data){              	           	          
                System.out.print("Trying to connect to EventCatcher");                            	       
                Client c = new Client(sendToHost, sendToPort);
                try {
					c.sendNoResponseMessage(data);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	}
}
